
var $ = jQuery.noConflict();

$(document).ready(function () {
    /*
     * Esc
     */
    $(document).keyup(function (e)
    {
        if (e.keyCode == 27) {
            if($('#layer').is(':visible')){
                closeIframe();
            }
        }
    });
    
    /*
     * Ctrl
     */
    $(document).keydown(function (event) {
        if (event.which == "17")
            cntrlIsPressed = true;
    });

    $(document).keyup(function () {
        cntrlIsPressed = false;
    });

    var cntrlIsPressed = false;
});

function replaceAll(find, replace, str) {
  return str.replace(new RegExp(find, 'g'), replace);
}

function exportToExcel()
{
    var data = '<table border="1">' + replaceAll("'", "&apos;", jQuery("#Categrories").html().replace(/<a\/?[^>]+>/gi, '')) + '</table>';
    jQuery('body').prepend("<form method='post' action=" + 'exportexcel.php' + " style='display:none' id='Categroriesss'><input type='text' name='tableData' value='" + data + "' ></form>");

    jQuery('#Categroriesss').submit();//.remove();
    //setTimeout(function(){closeIframe();}, 5000);
    return false;
}
function exportToDoc()
{
    var data = '<table border="1" align="center">' + replaceAll("'", "&apos;", jQuery("#Categrories").html().replace(/<a\/?[^>]+>/gi, '')) + '</table>';
    jQuery('body').prepend("<form method='post' action=" + 'exportdoc.php' + " style='display:none' id='Categroriess'><input type='text' name='tableData' value='" + data + "' ></form>");
    jQuery('#Categroriess').submit();//.remove();
    //setTimeout(function(){closeIframe();}, 5000);
    return false;
}


function OpenPop(popUrl, heights, widths) {
    var popUrl = popUrl;
    window.scrollTo(0, 0);
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight + document.documentElement.scrollTop;
    var layer = document.createElement("div");
    layer.style.zIndex = 99999;
    layer.id = "layer";
    layer.style.position = "absolute";
    layer.style.top = "0px";
    layer.style.left = "0px";
    layer.style.height = document.documentElement.scrollHeight + "px";
    layer.style.width = width + "px";
    layer.style.backgroundColor = "black";
    layer.style.opacity = "0.75";
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=75)");
    document.body.style.position = "static";


    document.body.appendChild(layer);
    var iframe = document.createElement("iframe");

    iframe.name = "Export excel by nhatnv";
    iframe.id = "popup";
    iframe.src = popUrl;
    iframe.style.height = heights + "px";
    iframe.style.width = widths + "px";
    iframe.style.position = "fixed";
    iframe.style.zIndex = 999999;
    iframe.style.backgroundColor = "white";
    iframe.frameborder = "0";
    iframe.style.top = ((height + document.documentElement.scrollTop) / 2) - (heights / 2) + "px";
    iframe.style.left = (width / 2) - (widths / 2) + "px";
    document.body.appendChild(iframe);
}
function ClosePop() {
    var layer = document.getElementById("layer");
    var iframe = document.getElementById("popup");
    document.body.removeChild(layer); // remove layer
    document.body.removeChild(iframe); // remove div
}
function closeIframe() {
    window.parent.ClosePop();

}

function currentDate() {
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth() + 1; //January is 0!
    var H = today.getHours();
    var yyyy = today.getFullYear();
    var i = today.getMinutes();
    if (dd < 10) {
        dd = '0' + dd
    }
    if (mm < 10) {
        mm = '0' + mm
    }
    var today = yyyy + '/' + mm + '/' + dd;
    return today;
}